// ignore_for_file: depend_on_referenced_packages

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:retrofit/http.dart';
import 'package:dio/dio.dart';

import 'Initial.dart';

part 'EmployeeApi.g.dart';
part 'EmployeeApi.freezed.dart';
@RestApi()
abstract class EmployeeApi {

  factory EmployeeApi(Dio dio, {String baseUrl}) = _EmployeeApi;
  
  @GET("employees/me")
  Future<MeResponse> getMe();

}

const MAX_PASSWORD_LENGTH = 16;
const INITIAL_PASSWORD_LENGTH = 8;
const MIN_PASSWORD_LENGTH = INITIAL_PASSWORD_LENGTH;

@freezed
class UpdatePasswordRequest with _$UpdatePasswordRequest{

  const factory UpdatePasswordRequest({
    required String password,
  }) = _UpdatePasswordRequest;

  const UpdatePasswordRequest._();

  factory UpdatePasswordRequest.fromJson(Map<String, dynamic> json) => _$UpdatePasswordRequestFromJson(json);

}

EmployeeApi employeeApi = EmployeeApi(dio, baseUrl: baseUrl);

initialEmployeeApi(Dio dio, String baseUrl) {
  employeeApi = EmployeeApi(dio, baseUrl: baseUrl);
}


@freezed
class MeResponse with _$MeResponse{

  const factory MeResponse({
    required int id,
    required String name,
    required List<String> authorities,
  }) = _MeResponse;

  const MeResponse._();

  factory MeResponse.fromJson(Map<String, dynamic> json) => _$MeResponseFromJson(json);

  bool hasAuthority(String authority){
    return authorities.contains(authority);
  }

}